#include "StdAfx.h"
#include "mydomtree.h"

bool MyDOMTree::Update(IHTMLDocument2* pDoc)
{
	m_spDoc2=pDoc;
	return !!m_spDoc2;
}

//build the dom tree
void MyDOMTree::BuildTree()
{	
	CComQIPtr<IHTMLDocument3> spDoc3 = m_spDoc2;
	ASSERT(spDoc3 != NULL);

	CComPtr<IHTMLElement> spRootElement;
	ASSERT( SUCCEEDED( spDoc3->get_documentElement( &spRootElement)) );

	CComQIPtr<IHTMLDOMNode> spRootNode = spRootElement;
	ASSERT(spRootNode != NULL);
	m_pDOMNodeRoot = new DOMNode(spRootNode);
	m_pDOMNodeRoot->AddChildren();
	m_pDOMNodeRoot->CalcTreeInfo();

#if 0
	ASSERT(m_pDOMNodeRoot->Contains("body"));
	ASSERT(m_pDOMNodeRoot->Contains("#text"));
	ASSERT(m_pDOMNodeRoot->Contains("td"));
	//	ASSERT(m_pDOMNodeRoot->Contains("dasdf"));//will produce an assert here
	CString strInfo;
	strInfo.Format("text length:%d,link num:%d",m_pDOMNodeRoot->m_nTextLength,m_pDOMNodeRoot->m_nLinkNum);
	//AfxMessageBox(strInfo);
	DOMNode* pDiffColor = m_pDOMNodeRoot->m_Children[1]->m_Children[0]->DiffBkChild();
	ASSERT(pDiffColor);
	AfxMessageBox(pDiffColor->m_TagName);
#endif
}